package com.wcl.demo.ui.activity;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.wcl.demo.R;

/**
 * Created by dllo on 15/12/5.
 */
public class MineHelpActivity extends Activity implements View.OnClickListener {
    private TextView  mine_help_verson_numBtn;
    private RelativeLayout mine_help_check_netBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_help);
        initView();
        initData();
    }

    private void initData() {

    }

    private void initView() {
        mine_help_check_netBtn = (RelativeLayout) findViewById(R.id.mine_help_check_netBtn);
        mine_help_check_netBtn.setOnClickListener(this);

//        mine_help_verson_numBtn = (TextView) findViewById(R.id.mine_help_verson_numBtn);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.mine_help_check_netBtn:
                if (isNetworkConnected(this)) {
                    Toast.makeText(this, "网络连接正常", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(this, "无网络可用", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }

    public boolean isNetworkConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
            if (mNetworkInfo != null) {
                return mNetworkInfo.isAvailable();
            }
        }
        return false;
    }
}
